#pragma once
#ifndef __GLF_DEBUGGER_XML_H__
#define __GLF_DEBUGGER_XML_H__

#include <glf/config.h>

#if GLF_ENABLE_DEBUGGER

#include <string>
#include <map>
#include <vector>

namespace glf
{
namespace debugger
{
typedef std::map<std::string, std::string> StringMap;
typedef std::pair<std::string, std::string> StringPair;
typedef std::vector<StringPair> StringPairVector;

class XmlReader
{
public:
	class Handler
	{
	public:
		virtual ~Handler() {}
		virtual void BeginTag(StringMap& tagAttr) = 0;
		virtual void EndTag(const std::string& id) {}
	};

	XmlReader(Handler* handler) : mHandler(handler) {}
	bool ParseTag(StringMap& tagAttr, const char* tagBuffer);
	void Parse(const std::string& xml);

private:
	Handler* mHandler;
};

class XmlWriter
{
public:
	XmlWriter();

	void BeginTag(const std::string& id);
	void BeginTag(const std::string& id, StringPairVector& tagAttr);
	void EndTag();
	const std::string& GetXml() const { return mXml; }

	struct Tag
	{
		bool mChild;
		std::string mId;
	};

	std::vector<Tag> mStack;
	std::string mXml;
};

} // end namespace debugger
} // end namespace glf

#endif // GLF_ENABLE_DEBUGGER

#endif // __GLF_DEBUGGER_XML_H__
